package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.servercenter.CrossServerGroup;
import com.yanqu.road.entity.servercenter.ServerGroup;
import com.yanqu.road.entity.servercenter.ServerGroup2;
import com.yanqu.road.entity.servercenter.group.CrossMarriageGroup;
import com.yanqu.road.pb.cross.group.CrossGroupProto;

import java.util.ArrayList;
import java.util.List;

public class CrossGroupPb {

    public static CrossGroupProto.AreaMammonGroupMsg.Builder parseAreaMammonGroupMsg(ServerGroup2 serverGroup2) {
        CrossGroupProto.AreaMammonGroupMsg.Builder builder = CrossGroupProto.AreaMammonGroupMsg.newBuilder();
        if (serverGroup2 != null) {
            builder.setGroupId(serverGroup2.getGroupId());
            builder.addAllServerList(serverGroup2.getServerList());
        } else {
            builder.setGroupId(0);
            builder.addAllServerList(new ArrayList<>());
        }
        return builder;
    }

    public static CrossGroupProto.CrossGroupTempMsg.Builder parseCrossGroupTempMsg(ServerGroup serverGroup){
        if(null == serverGroup){
            return null;
        }
        CrossGroupProto.CrossGroupTempMsg.Builder msg = CrossGroupProto.CrossGroupTempMsg.newBuilder();
        msg.setGroupId(serverGroup.getGroupId());
        msg.setIsCrossChat(serverGroup.isCrossChat());
        msg.setIsCrossRank(serverGroup.isCrossRank());
        msg.setCrossMammonState(serverGroup.getCrossMammonState());
        msg.addAllServerList(serverGroup.getServerList());
        return msg;
    }

    public static CrossGroupProto.CrossGroupListMsg.Builder parseCrossGroupListMsg(List<ServerGroup> serverGroupList){
        CrossGroupProto.CrossGroupListMsg.Builder listMsg = CrossGroupProto.CrossGroupListMsg.newBuilder();
        if(null != serverGroupList){
            for(ServerGroup serverGroup : serverGroupList){
                CrossGroupProto.CrossGroupTempMsg.Builder msg = parseCrossGroupTempMsg(serverGroup);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }


    public static CrossGroupProto.CrossGroupTypeTempMsg.Builder parseCrossGroupTypeTempMsg(CrossServerGroup serverGroup){
        if(null == serverGroup){
            return null;
        }
        CrossGroupProto.CrossGroupTypeTempMsg.Builder msg = CrossGroupProto.CrossGroupTypeTempMsg.newBuilder();
        msg.setGroupId(serverGroup.getGroupId());
        msg.setCrossZsState(serverGroup.getCrossZsState());
        msg.addAllServerList(serverGroup.getServerList());
        return msg;
    }

    public static CrossGroupProto.CrossGroupTypeListMsg.Builder parseCrossGroupTypeListMsg(List<CrossServerGroup> serverGroupList){
        CrossGroupProto.CrossGroupTypeListMsg.Builder listMsg = CrossGroupProto.CrossGroupTypeListMsg.newBuilder();
        if(null != serverGroupList){
            for(CrossServerGroup serverGroup : serverGroupList){
                CrossGroupProto.CrossGroupTypeTempMsg.Builder msg = parseCrossGroupTypeTempMsg(serverGroup);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static CrossGroupProto.CrossMarriageGroupListMsg.Builder parseCrossMarriageGroupListMsg(List<CrossMarriageGroup> marriageGroupList){
        CrossGroupProto.CrossMarriageGroupListMsg.Builder listMsg = CrossGroupProto.CrossMarriageGroupListMsg.newBuilder();
        if(null != marriageGroupList){
            for(CrossMarriageGroup marriageGroup : marriageGroupList) {
                CrossGroupProto.CrossMarriageGroupTempMsg.Builder msg = parseCrossMarriageGroupTempMsg(marriageGroup);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static CrossGroupProto.CrossMarriageGroupTempMsg.Builder parseCrossMarriageGroupTempMsg(CrossMarriageGroup marriageGroup){
        if(null == marriageGroup){
            return null;
        }
        CrossGroupProto.CrossMarriageGroupTempMsg.Builder msg = CrossGroupProto.CrossMarriageGroupTempMsg.newBuilder();
        msg.setGroupId(marriageGroup.getGroupId());
        msg.addAllServerList(marriageGroup.getServerList());
        msg.setIsCrossMarriage(marriageGroup.isCrossMarriage());
        msg.setIsCrossBanquet(marriageGroup.isCrossBanquet());
        return msg;
    }
}
